// pages/jiechedanbox/checkDetail/checkDetail.js
import {
  getCheckDetail,
  addChecker
} from '../../../utils/networkRequest.js'
import { errorMsg } from '../../../utils/tool.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    checkOrder: null,
    checkOrderID: "",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let self = this;
    self.setData({
      checkOrderID: options.id
    })
  },
  onShow: function () {
    let self = this;
    getCheckDetail(this.data.checkOrderID, (r) => {
      console.log(r)
      if (r.code == 0) {
        self.setData({
          checkOrder: r.data
        })
      } else {
        errorMsg(r.message)
      }
    })
  },
  //跳转到开始施工
  goWokerSelect: function () {
    let { checkOrder } = this.data;
    let carInfo = {};
    carInfo = Object.assign(carInfo, checkOrder.creator, checkOrder.auto);
    carInfo.score = checkOrder.score
    wx.navigateTo({
      url: "../checkWokerSelect/checkWokerSelect?checkId=" + checkOrder.id + "&carInfo=" + JSON.stringify(carInfo)
    })
  },
  //添加自己为检测人
  addCheckers: function () {

    let self = this;
    let {
      checkOrder
    } = this.data;

    wx.showModal({
      title: '提示',
      content: '确定要将自己添加为检测人员吗？',
      success: function (res) {
        if (res.confirm) {
          addChecker(checkOrder.id, "", (r) => {
            debugger;
            if (r.code == 0) {
              checkOrder.worker = r.data.checkers;
              checkOrder.im_in = r.data.im_in;
              self.setData({
                checkOrder: checkOrder,
              })
            }
          })
        } else if (res.cancel) {
          //点击取消
        }
      }
    })
  }
})